App({
    globalData:{
    },
    onLaunch: function() {
      var that = this
      wx.getUserInfo({
        success: function (res) {
          var userInfo = res.userInfo
          var nickName = userInfo.nickName
          var avatarUrl = userInfo.avatarUrl
          wx.login({
            success: function (res) {
              if (res.code) {
                //发起网络请求
                wx.request({
                  url: 'https://qili.docdic.com/api/user',
                  method:'post',
                  data: {
                    code: res.code,
                    nickname: nickName,
                    avatar: avatarUrl
                  },
                  success:function(response){
                    console.log(response)
                    if (Number(response.data.status) === 201){
                      let data = response.data.data
                      // wx.setStorage({
                      //   key: "token",
                      //   data:data.token
                      // })
                      wx.setStorageSync('token', data.token)
                      wx.setStorageSync('userId', data.user_id)
                      // wx.setStorage({
                      //   key: "userId",
                      //   data: data.user_id
                      // })
                    }
                  }
                })
              } else {
                console.log('获取用户登录态失败！' + res.errMsg)
              }
            }
          });
        }
      })
    }
})